package com.example.administrator.daydayappmarket.search.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.daydayappmarket.R;
import com.example.administrator.daydayappmarket.search.moduls.SearchActivityParent;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2017/1/13.
 */

public class SearchFragmentFirst1GridViewAdapter extends BaseAdapter {
    private List<SearchActivityParent> data;
    private Context context;

    public SearchFragmentFirst1GridViewAdapter(Context context, List<SearchActivityParent> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data != null ? data.size() : 0;
    }

    @Override
    public SearchActivityParent getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_search_fragment_first1_gridview, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        SearchActivityParent item = getItem(position);
        viewHolder.textView.setText(item.getTitle());

        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.item_search_fragment_first1_gridView_textView)
        TextView textView;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
            textView = (TextView) view.findViewById(R.id.item_search_fragment_first1_gridView_textView);
        }
    }
}
